package cn.sxt.yxl.controller.head;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.sxt.yxl.common.controller.BaseController;
import cn.sxt.yxl.common.util.ConstatFinalUtil;
import cn.sxt.yxl.common.util.PageInfoUtil;
import cn.sxt.yxl.question.pojo.AColumns;
import cn.sxt.yxl.question.pojo.AColumnsEnum;
import cn.sxt.yxl.question.pojo.AItems;
import cn.sxt.yxl.question.pojo.AItemsEnum;
import cn.sxt.yxl.question.service.IQuestionService;

/**
 * 首页的Contrller
 * 不需要登陆
 * @author YY
 *
 */
@Controller
public class IndexHeadController extends BaseController{
	@Resource
	private IQuestionService questionService;
	
	
	/**
	 * 首页
	 * @return
	 */
	@RequestMapping("/main")
	public String main(HttpServletRequest request){
		ConstatFinalUtil.LOGGER.info("---- main ----");
		return "/head/main" ; 
	}
	
	/**
	 * 栏目下面的测试项列表页面
	 * @param url 栏目的URL
	 * @return
	 */
	@RequestMapping("/{url}")
	public String itemsList(HttpServletRequest request,@PathVariable String url){
		ConstatFinalUtil.LOGGER.info("---- itemList --url:{}--",url);
		Map<String, Object> condMap = new HashMap<String, Object>();
		/* 查询url对应的栏目 */
		condMap.clear();
		condMap.put("url", url);
		AColumns columns = this.questionService.findOneColumnsService(condMap);
		request.setAttribute("columns", columns);
		/* 分页信息 */
		PageInfoUtil pageInfoUtil = this.proccedPageInfo(request);
		/* 查询url对应的栏目下面的测试项信息
		 * 启用 */
		condMap.clear();
		condMap.put("status", AItemsEnum.STATUS_ENABLE.getStatus());
		List<AItems> itemsList = this.questionService.findItemsCondListService(pageInfoUtil, condMap);
		/* 测试项列表 */
		request.setAttribute("pageInfoUtil", pageInfoUtil);
		request.setAttribute("itemsList", itemsList);
		return "/head/itemsList" ; 
	}
	

	/**
	 * 查询所有的栏目
	 * @return
	 */
	@RequestMapping("/header")
	public String header(HttpServletRequest request){
		/* 接收一个参数 */
		String id = request.getParameter("id");
		ConstatFinalUtil.LOGGER.info("---- header ---id:{}-",id);
		/* 将所有的栏目查询出来 */
		Map<String, Object> condMap = new HashMap<String, Object>();
		/* 只查询状态为启用的 */
		condMap.put("status", AColumnsEnum.STATUS_ENABLE.getStatus());
		List<AColumns> columnsList = this.questionService.findCondListColumnsService(null, condMap );
		/* 将查询出的结果放到Request中 */
		request.setAttribute("columnsList", columnsList);
		/*return "../../common/include/header" ;*/
		return "/head/header" ;
	}
}
